package cn.kgc.javase.collection;

/**
 * @author 课工场
 * @date 2024/8/15
 * @description
 */
public class StringDemo {

    public static void main(String[] args) {

        String  info = "hello";  //  不可变
        String  info2 = "hello";
        String  info3 = new String("hello");
        String  info4 = new String("hello");

        System.out.println(info==info2);  //  true
        System.out.println(info==info3);  //  false
        System.out.println(info4==info3);  //  false


        String upperCase = info.toUpperCase();
        System.out.println("upperCase = " + upperCase);
        System.out.println("info = " + info);

        // 线程安全
        StringBuffer stringBuffer = new StringBuffer();
        // 线程不安全的  字符串需要经常改变时
        StringBuilder stringBuilder = new StringBuilder("hello world");
        System.out.println("stringBuilder = " + stringBuilder);
        StringBuilder stringBuilder1 = stringBuilder.append("你好");
        System.out.println("stringBuilder1 = " + stringBuilder1);
        System.out.println("stringBuilder = " + stringBuilder);


    }
}
